package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark28Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class Mark28 extends BaseMark {

    LayoutWatermark28Binding binding;

    public Mark28(@NonNull Context context) {
        super(context);
    }

    public Mark28(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark28(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark28Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark28Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding2, "time28", "13", binding.binding1);
        if (setTime(binding.binding2, new SimpleDateFormat("HH:mm"))) {
            String[] ss = binding.binding2.getText().toString().split(":");
            binding.binding2.setText(ss[0]);
            binding.binding3.setText(ss[1]);
        }
        setTime(binding.binding5, new SimpleDateFormat("yyyy/MM/dd"));
        setWeek(binding.binding6);
        setText(binding.binding7, "didian28", binding.binding7);
        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("time28", "时间", true));
        list.add(new EditItem("didian28", "地点"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            if (setTime(binding.binding2, new SimpleDateFormat("HH:mm"))) {
                String[] ss = binding.binding2.getText().toString().split(":");
                binding.binding2.setText(ss[0]);
                binding.binding3.setText(ss[1]);
            }
            setTime(binding.binding5, new SimpleDateFormat("yyyy/MM/dd"));
            setWeek(binding.binding6);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isTime) {
            if (item.show) {
                showView(binding.binding1, binding.binding4);
            } else {
                hideView(binding.binding1, binding.binding4);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
